package com.xm.xmapp.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.xm.xmapp.R;

public class BigcustomerTipDialog extends Dialog {

	private Context context;
	private OnDaKeHuDialog onDaKeHuDialog;
	private TextView text;

	public void setOnDaKeHuDialog(OnDaKeHuDialog onDaKeHuDialog) {
		this.onDaKeHuDialog = onDaKeHuDialog;
	}

	public interface OnDaKeHuDialog {
		void accept();

		void refuse();
	}

	public BigcustomerTipDialog(Context context) {
		super(context, R.style.Dialog);	
		this.context = context;
	}

	@SuppressLint("InflateParams")
	public void init() {
		LayoutInflater inflater = LayoutInflater.from(context);
		View view = inflater.inflate(R.layout.dialog_bigcustomer, null);
		setContentView(view);
		text = (TextView) view.findViewById(R.id.text);
		view.findViewById(R.id.accept).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						dismiss();
						if (onDaKeHuDialog != null) {
							onDaKeHuDialog.accept();
						}
					}
				});

		view.findViewById(R.id.refuse).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						dismiss();
						if (onDaKeHuDialog != null) {
							onDaKeHuDialog.refuse();
						}
					}
				});

		Window dialogWindow = getWindow();
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高用
		lp.width = (int) (d.widthPixels * 0.8); // 高度设置为屏幕的0.6
		dialogWindow.setAttributes(lp);
	}

	public void setTextContent(String str) {
		if (text != null)
			text.setText("恭喜您！" + str + "诚挚邀您加入企业用车！");
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		init();
	}
}